support millisecond track moves (#1036)
authortsteven4 <13596209+tsteven4@users.noreply.github.com>
Wed, 15 Mar 2023 12:12:51 +0000 (06:12 -0600)
committerGitHub <noreply@github.com>
Wed, 15 Mar 2023 12:12:51 +0000 (06:12 -0600)
* support millisecond track moves

* add another position to track move option.

reference/track/trackfilter-move-z.gpx [new file with mode: 0644]
testo.d/track.test
trackfilter.cc
xmldoc/filters/options/track-move.xml

diff --git a/reference/track/trackfilter-move-z.gpx b/reference/track/trackfilter-move-z.gpx
new file mode 100644 (file)
index 0000000..3698b1f
--- /dev/null
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gpx version="1.0" creator="GPSBabel - https://www.gpsbabel.org" xmlns="http://www.topografix.com/GPX/1/0">
+  <time>1970-01-01T00:00:00Z</time>
+  <bounds minlat="30.046233000" minlon="-91.599283000" maxlat="30.046783000" maxlon="-91.598467000"/>
+  <trk>
+    <name>LOG-20020527</name>
+    <trkseg>
+      <trkpt lat="30.046233000" lon="-91.598467000">
+        <ele>0.000</ele>
+        <time>2002-05-27T19:02:48.005Z</time>
+      </trkpt>
+      <trkpt lat="30.046317000" lon="-91.598967000">
+        <ele>0.000</ele>
+        <time>2002-05-27T19:03:43.005Z</time>
+      </trkpt>
+      <trkpt lat="30.046783000" lon="-91.599283000">
+        <ele>0.000</ele>
+        <time>2002-05-27T19:04:49.005Z</time>
+      </trkpt>
+    </trkseg>
+  </trk>
+</gpx>
index cc1de5874d8f88a7bcac78f5014e64111afff1ad..adb9afbe18323790fcef5277774ae92cd22412ea 100644 (file)
@@ -54,6 +54,9 @@ compare ${REFERENCE}/track/trackfilter-move-d.gpx ${TMPDIR}/trackfilter-move-d.g
 gpsbabel -t -i gpx -f ${REFERENCE}/track/trackfilter.gpx -x track,move=-5m,name=LOG-20020527,start=20020527185742,stop=20020527185950,minimum_points=2 -o gpx -F ${TMPDIR}/trackfilter-move-m.gpx
 compare ${REFERENCE}/track/trackfilter-move-m.gpx ${TMPDIR}/trackfilter-move-m.gpx
 
+gpsbabel -t -i gpx -f ${REFERENCE}/track/trackfilter.gpx -x track,move=5z,name=LOG-20020527,start=20020527190141.5,stop=20020527190449.5,minimum_points=2 -o gpx -F ${TMPDIR}/trackfilter-move-z.gpx
+compare ${REFERENCE}/track/trackfilter-move-z.gpx ${TMPDIR}/trackfilter-move-z.gpx
+
 # actually test a merge
 gpsbabel -t -i gpx -f ${REFERENCE}/track/trackfilter_merge.gpx -x track,merge -x track,speed -o gpx -F ${TMPDIR}/trackfilter_merge~gpx.gpx
 compare ${REFERENCE}/track/trackfilter_merge~gpx.gpx ${TMPDIR}/trackfilter_merge~gpx.gpx
index f63b1359c7333d6c18d48bd553a89a97a8fc4c82..a690a6c79c205882c71718ba2eb5d1ecee0af1fd 100644 (file)
@@ -75,7 +75,7 @@ qint64 TrackFilter::trackfilter_parse_time_opt(const char* arg)
 {
   qint64 result = 0;
 
-  static const QRegularExpression re(R"(^([+-]?\d+)([wdhms])(?:([+-]?\d+)([wdhms]))?(?:([+-]?\d+)([wdhms]))?(?:([+-]?\d+)([wdhms]))?(?:([+-]?\d+)([wdhms]))?$)", QRegularExpression::CaseInsensitiveOption);
+  static const QRegularExpression re(R"(^([+-]?\d+)([wdhmsz])(?:([+-]?\d+)([wdhmsz]))?(?:([+-]?\d+)([wdhmsz]))?(?:([+-]?\d+)([wdhmsz]))?(?:([+-]?\d+)([wdhmsz]))?(?:([+-]?\d+)([wdhmsz]))?$)", QRegularExpression::CaseInsensitiveOption);
   assert(re.isValid());
   QRegularExpressionMatch match = re.match(arg);
   if (match.hasMatch()) {
@@ -89,18 +89,21 @@ qint64 TrackFilter::trackfilter_parse_time_opt(const char* arg)
 
       switch (match.captured(idx+1).at(0).toLower().toLatin1()) {
       case 'w':
-        partial *= SECONDS_PER_DAY * 7;
+        partial *= SECONDS_PER_DAY * 1000 * 7;
         break;
       case 'd':
-        partial *= SECONDS_PER_DAY;
+        partial *= SECONDS_PER_DAY * 1000;
         break;
       case 'h':
-        partial *= SECONDS_PER_HOUR;
+        partial *= SECONDS_PER_HOUR * 1000;
         break;
       case 'm':
-        partial *= 60;
+        partial *= 60 * 1000;
         break;
       case 's':
+        partial *= 1000;
+        break;
+      case 'z':
         break;
       default:
         fatal(MYNAME "-time: invalid unit in move option \"%s\"!\n", qPrintable(match.captured(idx+1)));
@@ -110,7 +113,7 @@ qint64 TrackFilter::trackfilter_parse_time_opt(const char* arg)
 
     }
 #ifdef TRACKF_DBG
-    qDebug() << MYNAME "-time option: shift =" << result << "seconds";
+    qDebug() << MYNAME "-time option: shift =" << result / 1000.0 << "seconds";
 #endif
   } else {
     fatal(MYNAME "-time: invalid value in move option \"%s\"!\n", arg);
@@ -579,7 +582,7 @@ void TrackFilter::trackfilter_move()
   for (auto* track : qAsConst(track_list)) {
     foreach (Waypoint* wpt, track->waypoint_list) {
       if (wpt->creation_time.isValid()) {
-        wpt->creation_time = wpt->creation_time.addSecs(delta);
+        wpt->creation_time = wpt->creation_time.addMSecs(delta);
       } else {
         ++timeless_points;
       }
index c7a09cb846a2ddd5454985b26258d1b3ce9ee653..8ce1248ce837ce5ec86b19c582f08fc3192e0de8 100644 (file)
@@ -8,7 +8,7 @@ It can also be useful to correct tracks for week number roll over problems.
 The value of this option is a series of integer and unit pairs.  Each integer may include a
 leading '+' or '-' sign.  Positive integers shift the tracks later, while negative integers shift
 the tracks earlier.  If no sign is provided the integer is assumed to be nonnegative.
-Possible units are w for weeks, d for days, h for hours, m for minutes and s for seconds.
+Possible units are w for weeks, d for days, h for hours, m for minutes, s for seconds and z for milliseconds.
 </para>
 <example xml:id="ex_track_move">
 <title>Time-shifting a track with the track filter</title>